package com.ruoyi.purchase.domain;

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单维护对象 purchase_order
 *
 * @author kevinness
 * @date 2025-01-02
 */
public class PurchaseOrder extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 采购订单编号
     */
    @Excel(name = "采购订单编号")
    private String orderNo;

    /**
     * 供货商名称
     */
    @Excel(name = "供货商名称")
    private String companyName;

    /**
     * 交货地点
     */
    private String deliveryAddress;

    /**
     * 交货地点经度
     */
    private double destinationLng;

    /**
     * 交货地点纬度
     */
    private double destinationLat;

    /**
     * 下单时间
     */
    @Excel(name = "下单时间")
    private String orderTime;

    /**
     * 采购负责人
     */
    private String responsiblePerson;

    /**
     * 联系电话
     **/
    private String contactPhone;

    /**
     * 订单状态
     */
    @Excel(name = "订单状态")
    private String orderStatus;

    /**
     * 修改日期
     */
    @Excel(name = "修改日期")
    private String modifiedDate;

    /**
     * 修改人
     */
    @Excel(name = "修改人")
    private String modifiedBy;

    /**
     * 生成订单操作人
     */
    private String operator;

    /**
     * 备注
     */
    @Excel(name = "备注")
    private String remarks;

    /**
     * 记录字段到中文的映射
     */
    private static final Map<String, String> fieldToChineseName = new HashMap<>();

    // 静态初始化块，用于初始化映射
    static {
        fieldToChineseName.put("orderNo", "订单编号");
        fieldToChineseName.put("companyName", "供货商名称");
        fieldToChineseName.put("deliveryAddress", "交货地点");
        fieldToChineseName.put("orderTime","下单时间");
        fieldToChineseName.put("responsiblePerson","采购负责人");
        fieldToChineseName.put("contactPhone","联系电话");
        fieldToChineseName.put("orderStatus","订单状态");
        fieldToChineseName.put("modifiedDate","修改日期");
        fieldToChineseName.put("modifiedBy","修改人");
        fieldToChineseName.put("operator","操作人");
        fieldToChineseName.put("remarks","备注");
    }
    public PurchaseOrder() {}

    public PurchaseOrder(String orderNo, String companyName, String deliveryAddress, String orderTime, String responsiblePerson, String contactPhone, String orderStatus, String modifiedDate, String modifiedBy, String remarks) {
        this.orderNo = orderNo;
        this.companyName = companyName;
        this.deliveryAddress = deliveryAddress;
        this.orderTime = orderTime;
        this.responsiblePerson = responsiblePerson;
        this.contactPhone = contactPhone;
        this.orderStatus = orderStatus;
        this.modifiedDate = modifiedDate;
        this.modifiedBy = modifiedBy;
        this.remarks = remarks;
    }

    public PurchaseOrder(PurchaseOrderParams params) {
        this.orderNo = params.getOrderNo();
        this.companyName = params.getCompanyName();
        this.deliveryAddress = params.getDeliveryAddress();
        this.destinationLng = params.getDestinationLng();
        this.destinationLat = params.getDestinationLat();
        this.orderTime = params.getOrderTime();
        this.responsiblePerson = params.getResponsiblePerson();
        this.contactPhone = params.getContactPhone();
        this.orderStatus = params.getOrderStatus();
        this.modifiedDate = params.getModifiedDate();
        this.modifiedBy = params.getModifiedBy();
        this.remarks = params.getRemarks();
    }

    public PurchaseOrder(ChangeDetail detail) {
        this.orderNo = detail.getOrderNo();
        this.responsiblePerson = detail.getResponsiblePerson();
        this.contactPhone = detail.getContactPhone();
        this.deliveryAddress = detail.getDeliveryAddress();
        this.destinationLng = detail.getDestinationLng();
        this.destinationLat = detail.getDestinationLat();
        this.remarks = detail.getRemarks();
        this.modifiedBy = detail.getChangePerson();
        this.modifiedDate = detail.getChangeTime();
    }

    //查询中文名称
    public static String getChineseFieldName(String fieldName) {
        return fieldToChineseName.getOrDefault(fieldName, "未知属性");
    }

    public static List<ChangeRecord> comparePurchaseOrder(PurchaseOrder oldOrder, PurchaseOrder newOrder) {
        List<ChangeRecord> changeRecords = new ArrayList<>();
        if(!oldOrder.getResponsiblePerson().equals(newOrder.getResponsiblePerson())){
            changeRecords.add(new ChangeRecord("采购负责人",oldOrder.getResponsiblePerson(),newOrder.getResponsiblePerson()));
        }
        if(!oldOrder.getContactPhone().equals(newOrder.getContactPhone())){
            changeRecords.add(new ChangeRecord("联系电话",oldOrder.getContactPhone(),newOrder.getContactPhone()));
        }
        if(!oldOrder.getDeliveryAddress().equals(newOrder.getDeliveryAddress())){
            changeRecords.add(new ChangeRecord("交货地点",oldOrder.getDeliveryAddress(),newOrder.getDeliveryAddress()));
        }
        if(!oldOrder.getRemarks().equals(newOrder.getRemarks())){
            changeRecords.add(new ChangeRecord("备注",oldOrder.getRemarks(),newOrder.getRemarks()));
        }
        return changeRecords;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setDeliveryAddress(String deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }

    public String getDeliveryAddress() {
        return deliveryAddress;
    }

    public double getDestinationLng() {
        return destinationLng;
    }

    public void setDestinationLng(double destinationLng) {
        this.destinationLng = destinationLng;
    }

    public double getDestinationLat() {
        return destinationLat;
    }

    public void setDestinationLat(double destinationLat) {
        this.destinationLat = destinationLat;
    }

    public void setOrderTime(String orderTime) {
        this.orderTime = orderTime;
    }

    public String getOrderTime() {
        return orderTime;
    }

    public void setResponsiblePerson(String responsiblePerson) {
        this.responsiblePerson = responsiblePerson;
    }

    public String getResponsiblePerson() {
        return responsiblePerson;
    }

    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }

    public String getOrderStatus() {
        return orderStatus;
    }

    public void setModifiedDate(String modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    public String getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public String getModifiedBy() {
        return modifiedBy;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getRemarks() {
        return remarks;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("orderNo", getOrderNo())
                .append("companyName", getCompanyName())
                .append("deliveryAddress", getDeliveryAddress())
                .append("destinationLng", getDestinationLng())
                .append("destinationLat", getDestinationLat())
                .append("orderTime", getOrderTime())
                .append("responsiblePerson", getResponsiblePerson())
                .append("contactPhone", getContactPhone())
                .append("orderStatus", getOrderStatus())
                .append("modifiedDate", getModifiedDate())
                .append("modifiedBy", getModifiedBy())
                .append("operator", getOperator())
                .append("remarks", getRemarks())
                .toString();
    }
}
